import { APP_FLIGHT_PATH, callService } from '@/common/common.js'

// 上传文件
export function uploadFile(params, cbDone, cbAlways, cbFail) {
  const url = APP_FLIGHT_PATH + '/upload/'
  callService(url, {
    data: params,
    contentType: false,
    cache: false,
    processData: false,
    timeout: 0,
    cbDone: cbDone,
    cbFail: cbFail,
    cbAlways: cbAlways
  })
}

export function getUploadToken(params, done, fail, always) {
  $.ajax({
    type: "post",
    url: "/Flight/upload/uploadToken",
    dataType: "text"
  }).done(function (jsonResult) {
    done(jsonResult)
  }).fail(function (jqXHR, textStatus, errorThrown) {
    fail(jqXHR.status, jqXHR.statusText)
  }).always(function () {
    always()
  })
}

export function locallySaveKey(key, done, fail, always) {
  $.ajax({
    type: "post",
    url: "/Flight/material/local-save",
    dataType: "text",
    data: { 'key': key }
  }).done(function (jsonResult) {
    // done(jsonResult)
  }).fail(function (jqXHR, textStatus, errorThrown) {
    // fail(jqXHR.status, jqXHR.statusText)
  }).always(function () {
    // always()
  })
}